package com.woniuxy.kaer.service.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.kaer.service.dto.ServiceEvaluateDto;
import com.woniuxy.kaer.service.entity.ServiceBase;
import com.woniuxy.kaer.service.entity.ServiceEvaluate;
import com.woniuxy.kaer.service.entity.ServiceOrder;
import com.woniuxy.kaer.service.mapper.ServiceBaseMapper;
import com.woniuxy.kaer.service.mapper.ServiceEvaluateMapper;
import com.woniuxy.kaer.service.mapper.ServiceOrderMapper;
import com.woniuxy.kaer.service.service.ServiceEvaluateService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 程诗洋
 * @since 2025年02月17日
 */
@Service
public class ServiceEvaluateServiceImpl extends ServiceImpl<ServiceEvaluateMapper, ServiceEvaluate> implements ServiceEvaluateService {

    @Resource
    private ServiceEvaluateMapper serviceEvaluateMapper;
    @Resource
    private ServiceOrderMapper serviceOrderMapper;
    @Resource
    private ServiceBaseMapper serviceBaseMapper;
    @Override
    public List<ServiceEvaluateDto> getServiceEvaluateByShopId(String shopId) throws Exception {
        ArrayList<ServiceEvaluateDto> serviceEvaluateDtos = new ArrayList<>();
        QueryWrapper<ServiceEvaluate> serviceEvaluateQueryWrapper = new QueryWrapper<>();
        serviceEvaluateQueryWrapper.eq("shop_id",shopId);
        List<ServiceEvaluate> serviceEvaluateList = serviceEvaluateMapper.selectList(serviceEvaluateQueryWrapper);
        for (ServiceEvaluate serviceEvaluate : serviceEvaluateList) {
            ServiceEvaluateDto serviceEvaluateDto = BeanUtil.toBean(serviceEvaluate, ServiceEvaluateDto.class);
            QueryWrapper<ServiceOrder> serviceOrderQueryWrapper = new QueryWrapper<>();
            serviceOrderQueryWrapper.eq("service_order_id",serviceEvaluate.getServiceOrderId());
            ServiceOrder serviceOrder = serviceOrderMapper.selectOne(serviceOrderQueryWrapper);
            ServiceBase serviceBase = serviceBaseMapper.selectById(serviceOrder.getServiceBaseId());
            serviceEvaluateDto.setServiceBaseName(serviceBase.getServiceBaseName());
            serviceEvaluateDtos.add(serviceEvaluateDto);
        }
        return serviceEvaluateDtos;
    }
}
